<?php 
include_once 'function.php';

$error1 = '<!DOCTYPE HTML><html><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8" />'.
		'<meta http-equiv="Refresh" content="5;url=/"/></head>'.
		'<body style="text-align:center;">';
$error2 = '</body></html>';
if (!isset($_SESSION['id']) || empty($_SESSION['id']))
{
	echo $error1.'木有权限观赏视频<br />请<a href="/login.php">登录</a>，如果没有帐号请<a href="/register.php">免费注册</a>'.$error2;
	exit;
}

if (!isset($_GET['id']) || empty($_GET['id']))
{
	echo $error1.'视频不存在'.$error2;
	exit;
}

$id = $_GET['id'];
$conn = conn();
$sql = "SELECT img, free FROM films WHERE id = ".mysql_real_escape_string($id, $conn);
$result = mysql_query($sql, $conn);
$row = mysql_fetch_assoc($result);
if (!isset($row['img']))
{
	echo $error1.'视频不存在'.$error2;
	exit;
}
if (0 == $row['free'])
{
	if (!check_permission())
	{
		header('Location:/price.php');
		exit;
	}
}
$img = $row['img'];
?>
<!DOCTYPE HTML>
<html>
	<head>
		<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
		<meta name="viewport" content="width=device-width; initial-scale=1.0; maximum-scale=1.0;" />
		<link rel="stylesheet" type="text/css" href="/theme.css" />
		<script language="javascript">
		// change the page width according to orientation
		var updateOrientation = function(){
			if ('undefined' != typeof window.orientation)
			{
				var className = 'wrapper_';
				switch(window.orientation){
					case 0:
						className += 'portrait';
						break;
					case -90:
						className += 'landscape';
						break;
					case 90:
						className += 'landscape';
						break;
					case 180:
						className += 'portrait';
						break;
				}
				document.getElementById('wrapper').setAttribute('class', className);
			}
		}
		window.onload = updateOrientation;
		window.onorientationchange = updateOrientation;
		</script>
	</head>
	<body>
		<div class="wrapper_landscape">
			<video src="/get_film.php?id=<?php echo $id; ?>" controls="controls" poster="/imgs/<?php echo $img; ?>">
			Your browser does not support the video tag.
			</video>
			<div class="footer">
				<a href="/payment.php">支付方式</a>
				<a href="/price.php">服务价格</a>
				<a href="/contact.php">联系我们</a><br /><br />
				&copy; <?php echo SITE.' '.date('Y');?>
			</div>
		</div>
	</body>
</html>